package cn.wit.rank.controller;


import cn.wit.rank.service.RankService;
import cn.wit.utils.response.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.wit.utils.response.Result;
@RestController
@Api(tags = "成绩排行")
@CrossOrigin
@RequestMapping("/rank")
public class RankController {
    @Autowired
    private RankService rankService;

    @ApiOperation("初始化学习成绩榜单")
    @GetMapping("/studyRankMaker")
    public Result initStudyRank(){
        return rankService.initStudyRecordRank();

    }

    @GetMapping("/studyCompletenessRankMaker/#{className}")
    @ApiOperation("初始化完成度榜单")
    public Result initStudyCompletenessRank(@PathVariable(value = "className")String className){
        return rankService.initStudyCompletenessRank(className);

    }





    //评论区接口

    @GetMapping("/initStudyCommentArea")
    @ApiOperation("完成度排行榜评论区初始化")
    public Result initStudyCommentArea(@RequestParam String kind){


        return rankService.initinitStudyCommentArea(kind);
    }




    @GetMapping("/initCompletenessCommentArea#{className}")
    @ApiOperation("成绩评论区初始化")
    public Result initCompletenessCommentArea(@PathVariable String className){

        return rankService.initinitStudyCommentArea(className);
    }




    @DeleteMapping("/deleteComment")
    @ApiModelProperty("删除评论")
    public  Result deleteCommentController(@RequestParam("commentId") int id){


        return rankService.deleteCommentAreaItem(id);
    }//根据评论的主键删除评论，还要删除其被回复的





    @PostMapping("/createAttention")
    @ApiOperation("发布评论")
    public Result createAttention(@RequestParam("UserId") int UserId,@RequestParam String content,@RequestParam String kind){

        return rankService.createAttention(UserId,content,kind);

    }//Userip用于记录发布评论的用户




    @ResponseBody
    @PostMapping("/replyAttention")
    @ApiOperation("回复评论")
    public Result replyAttention(@RequestParam("UserIp") int UserIp,@RequestParam int repliedCommentIp,@RequestParam String content,@RequestParam String kind){
        return rankService.replyAttention(UserIp,repliedCommentIp,content,kind);

    }//Userip用于记录发布评论的用户,操作为添加一个评论，并在被回复的评论中加入


    @PostMapping("/initReplyCompletenessCommentArea")
    @ApiOperation("初始化回复的评论")
    public Result initReplyCompletenessCommentArea(@RequestParam long id){
      Result r=rankService.initReplyCompletenessCommentArea(id);
        return r;
    }


    @PutMapping("/like")
    @ApiOperation("点赞")
    public Result likeCompletenessCommentArea(@RequestParam long id){
        return rankService.likeCompletenessComment(id);
    }















}
